'use strict';

const Service = require('egg').Service;

class PermissionService extends Service {
  // 新增和更新
  async save(params) {
    const User = this.ctx.state.user;
    params.updateBy = User.name;
    if (params._id) {
      return this.ctx.model.Permission.findOneAndUpdate({ _id: params._id }, params, { upsert: true });
    }
    params.createBy = User.name;
    const saveDate = new this.ctx.model.Permission(params);
    return saveDate.save();

  }

  // 根据ids查询菜单
  async findById(ids) {
    return this.ctx.model.Permission.find({ _id: { $in: ids } });
  }
}

module.exports = PermissionService;
